package cn.com.hhrcw.web;

import cn.com.hhrcw.entity.SysUser;
import cn.com.hhrcw.login.LoginVO;
import cn.com.hhrcw.login.MobileCodeLogin;
import cn.com.hhrcw.params.LoginUserParams;
import cn.com.hhrcw.service.ISysUserService;
import cn.com.hhrcw.utils.SubjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @program: recruit-boot-parent
 *
 * @author: JD
 * @create: 2020-10-30 10:50
 **/
@RestController
@Slf4j
@Validated
public class PasswordController extends JeecgController<SysUser, ISysUserService> {

    /**
     * 登陆
     *
     * @param params
     * @return
     */
    @PostMapping("/personal/login")
    public Result<LoginVO> login(@RequestBody @Valid LoginUserParams params) {
        LoginVO vo = new LoginVO();
        SubjectUtils.login(new MobileCodeLogin(params.getMobile(), params.getPassword(), vo));
        return Result.success(vo);
    }

    /**
     * 退出登陆
     *
     * @return
     */
    @PostMapping("/personal/logout")
    public Result<Object> logout() {
        SubjectUtils.logout();
        return Result.ok("账号已退出");
    }

}
